package struts;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;

public class LoginCheckFilterDispatcher extends StrutsPrepareAndExecuteFilter {

	private Log log = LogFactory.getLog(this.getClass());
	
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		super.destroy();
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse res,
			FilterChain filter) throws IOException, ServletException {
		
		log.info("begin");
		
		HttpServletRequest request = (HttpServletRequest)req; 
		log.info(request.getContextPath());
		log.info(request.getRequestURL());
//		HttpServletResponse response = (HttpServletResponse)res;
//		String WebRoot = request.getContextPath();
//		String URI = request.getRequestURI();
//		String URL = request.getRequestURL().toString();

		request.getSession().setAttribute("UID", "admin");
		request.getSession().setAttribute("PWD", "admin");

		super.doFilter(req, res, filter);
		log.info("over");
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		super.init(arg0);
	}

}
